<layout name="Layout/layout" />
<div class="row">
	<div class="col-lg-12">
		<h1 class="page-header">考点</h1>
	</div>
	<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default">
			<div class="panel-heading">
				考点列表
				<a class="btn btn-default btn-xs pull-right" href="{:U('Admin/Examcenter/addexamcenter')}" role="button">
					<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
				</a>
			</div>
			<!-- /.panel-heading -->
			<div class="panel-body">
			<?php
				$head = array(
					'id'	=>	array('ID','doNothing'),
					'name'	=>	array('名称','doNothing'),
					'fromprovince'	=>	array('所属省份','getProvinceName'),
					'forprovince'	=>	array('考生省份','getProvinceNames'),
					'majors'	=>	array('支持专业','getMajorNames'),
					'start_time'	=>	array('考试开始时间', 'formatDate'),
					'end_time'	=>	array('考试结束时间', 'formatDate'),
					'inuse'	=>	array('启用','checkInuse'),
				);
			?>
			{:W('Table/tableWithFunction', array($head, $examcenterlist, C('OP_TYPE.OP_EDIT')|C('OP_TYPE.OP_DELETE')|C('OP_TYPE.OP_DEFINE_RULE')))}
			</div>
			<!-- /.panel-body -->
		</div>
		<!-- /.panel -->
	</div>
	<!-- /.col-lg-12 -->
</div>
<script>
	window.onload = function(){

		$.fn.bootstrapSwitch.defaults.onText = '启用中';
		$.fn.bootstrapSwitch.defaults.offText = '禁用中';
		$.fn.bootstrapSwitch.defaults.onColor = 'success';
		$.fn.bootstrapSwitch.defaults.offColor = 'warning';
		$("[name=isopen]").bootstrapSwitch();
		$('input[name="isopen"]').on('switchChange.bootstrapSwitch', function(event, state) {
		 	var id = $(this).parent().parent().parent().parent().prevAll().last().text();
			$.post("{:U('Admin/Examcenter/setStatus')}",{
				status: state,
				id: id
			},
			function(data, status){
				console.log(data);
			});
		});
		$('.btn-edit').click(function(){
			var id = $(this).parent().prevAll().last().text();
			window.location.href = "{:U('Admin/Examcenter/edit')}" + '?id=' + id;
		});
		$('.btn-delete').click(function(){
			var id = $(this).parent().prevAll().last().text();
		});
		$('.btn-rule').click(function(){
			var id = $(this).parent().prevAll().last().text();
			window.location.href = "{:U('Admin/Examcenter/rule')}" + '?id=' + id;
		});
		$('#dataTables-example').DataTable({
	            responsive: true
	    });
	}
</script>
